package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.AlbumDTO;
import com.andy.blog.admin.service.AlbumBusService;
import com.andy.blog.common.annotation.Log;
import com.andy.blog.common.enums.BusinessTypeEnum;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.vo.AlbumVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2023/10/15 16:24
 */
@RestController
public class AlbumController {

    @Resource
    private AlbumBusService albumBusService;

    /**
     * 查看相册列表
     */
    @GetMapping("/portal/album/list")
    public GeneralResponseResult<List<AlbumDTO>> listAlbumVO() {
        return GeneralResponseResult.success(albumBusService.listAlbumVO());
    }

    /**
     * 获取参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('portal:ablum:list')")
    @GetMapping("/album/listPage")
    public GeneralResponseResult<PageUtilsDTO<AlbumDTO>> listPage(AlbumVO albumVO) {
        return GeneralResponseResult.success(albumBusService.selectPage(albumVO));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('portal:ablum:add')")
    @Log(title = "相册管理", businessType = BusinessTypeEnum.INSERT)
    @PostMapping("/album")
    public GeneralResponseResult<Void> add(@Validated @RequestBody AlbumVO albumVO) {
        albumBusService.add(albumVO);
        return GeneralResponseResult.success();
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:sensitive:edit')")
    @Log(title = "修改", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/album")
    public GeneralResponseResult<Void> edit(@Validated @RequestBody AlbumVO albumVO) {
        albumBusService.updateById(albumVO);
        return GeneralResponseResult.success();
    }
}
